<template>
  <view class='my_page'>
    <!-- 我的 -->
    <view class='item_box'>
      <view hover-class='btn_hover2' v-for='(item,index) in list' :key='index'>
        <view>
          <image :src='"../../static/img/icon/my/"+index+".png"' mode='widthFix'></image>
          <text>{{item}}</text>
        </view>
        <text class='iconfont icon-jiantou-copy-copy'></text>
      </view>
    </view>
    <button class='btn' hover-class='btn_hover' @tap='clickLoginOut'>退出登录</button>

  </view>
</template>

<script>
  export default {
    data() {
      return {
        list: ["用户信息","预警推送设置","清除手机缓存","版本更新检查","字体选择"]
      }
    },

    methods: {
      // 退出登陆
      loginOut(token) {
        this.$http({
          url: this.$api.user.login_out,
          data: {
            token
          }
        }).then( res => {
          if(res.code == 0) {
            uni.removeStorageSync('token');
            uni.showToast({
              title: '您已退出登陆',
              icon: 'none'
            });
            setTimeout(() => {
              uni.reLaunch({
                url: '../login/login'
              });
            },2000)
          }
        })
      },
      // 点击退出登录
      clickLoginOut() {
        let self = this;
        uni.showModal({
            title: '提示',
            content: '确定退出登录吗？',
            success(res) {
              if (res.confirm) {
                uni.getStorage({
                  key: 'token',
                  success(res) {
                    self.loginOut(res.data)
                  },
                  fail() {
                    uni.reLaunch({
                      url: '../login/login'
                    });
                  }
                });
              }
            }
        });
      },
    }
  }
</script>

<style lang="scss" scoped>
.my_page {
  width: 100%;
  padding: 20upx;
  box-sizing: border-box;
  .item_box {
    width: 100%;
    border-radius: 12upx;
    background: #fff;
    margin-bottom: 50upx;
    >view {
      width: 100%;
      height: 100upx;
      border-bottom: 1px solid #eee;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 20upx;
      box-sizing: border-box;
      font-size: 30upx;
      color: #003333;
      &:nth-last-child(1) {
        border: none;
      }
      >view {
        display: flex;
        align-items: center;
        >image {
          width: 36upx;
          margin-right: 20upx;
        }
      }
      .iconfont {
        transform: rotate(-90deg);
      }
    }
  }
}
</style>